const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const UserBenefit = sequelize.define('UserBenefit', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    user_uuid: {
        type: DataTypes.UUID,
        allowNull: false,
        unique: true,
        comment: '用户UUID'
    },
    stripe_subscription_id: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: '当前有效的Stripe订阅ID'
    },
    subscription_status: {
        type: DataTypes.ENUM('active', 'cancelled', 'past_due', 'unpaid', 'incomplete', 'incomplete_expired'),
        allowNull: true,
        comment: 'Stripe订阅状态'
    },
    membership_tier: {
        type: DataTypes.INTEGER,
        allowNull: true,
        defaultValue: null,
        comment: '会员等级：1=一级会员，2=二级会员，3=三级会员，null=非会员'
    },
    total_tokens_purchased: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '累计购买的代币数量（不含订阅赠送）'
    },
    total_tokens_granted: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '累计通过订阅获得的代币数量'
    },
    total_tokens_used: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '累计使用的代币数量'
    }
}, {
    tableName: 'user_benefits',
    comment: '用户权益统计表'
});

module.exports = UserBenefit;